package com.zzy.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzy.commonutils.R;
import com.zzy.commonutils.ordervo.CourseWebVoOrder;
import com.zzy.edu.entity.EduCourse;
import com.zzy.edu.entity.vo.chapter.ChapterVo;
import com.zzy.edu.entity.vo.front.CourseFrontVo;
import com.zzy.edu.entity.vo.front.CourseWebVo;
import com.zzy.edu.service.EduChapterService;
import com.zzy.edu.service.EduCourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;

import java.util.List;
import java.util.Map;

/**
 * @Author KAZU
 * @Date 2023/1/20 15:57
 * @Version 1.0
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/eduservice/coursefront")
@CrossOrigin
public class CourseFrontController {
	
	@Autowired
	private EduCourseService courseService;
	
	@Autowired
	private EduChapterService chapterService;
	
	/**
	 * 条件查询带分页查询课程
	 * */
	@PostMapping("getFrontCourseList/{page}/{limit}")
	public R getFrontCourseList(@PathVariable Long page,
								@PathVariable Long limit,
								@RequestBody(required = false) CourseFrontVo courseFrontVo) {
		QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
		Page<EduCourse> coursePage = new Page<>(page, limit);
		Map<String, Object> map = courseService.getCourseFrontList(coursePage, courseFrontVo);
		return R.ok().data(map);
	}
	
	/**
	 * 课程详情方法
	 * */
	@GetMapping("getCourseInfo/{id}")
	public R getCourseInfo(@PathVariable String id) {
		// 根据课程id，编写sql语句查询课程信息
		CourseWebVo courseWebVo = courseService.getBaseCourseInfo(id);
		// 根据课程id，查询章节和小节
		List<ChapterVo> chapterVoList = chapterService.getChapterVideoByCourseId(id);
		return R.ok().data("courseWebVo", courseWebVo).data("chapterVoList", chapterVoList);
	}
	
	/**
	 * 根据课程id查询课程信息
	 * */
	@PostMapping("getCourseInfoOrder/{id}")
	public CourseWebVoOrder getCourseInfoOrder(@PathVariable String id) {
		CourseWebVo courseInfo = courseService.getBaseCourseInfo(id);
		CourseWebVoOrder order = new CourseWebVoOrder();
		BeanUtils.copyProperties(courseInfo, order);
		return order;
	}
	
}


















